<?php
///
///  composer 包
///  "endroid/qr-code": "^4.3"
///

namespace app\api\controller\v1\invite;

use Endroid\QrCode\Color\Color;
use Endroid\QrCode\Encoding\Encoding;
use Endroid\QrCode\ErrorCorrectionLevel\ErrorCorrectionLevelLow;
use Endroid\QrCode\QrCode;
use Endroid\QrCode\RoundBlockSizeMode\RoundBlockSizeModeMargin;
use Endroid\QrCode\Writer\PngWriter;



class makeQrcode
{

    public function Index()
    {

        $writer = new PngWriter();
        // Create QR code
        $qrCode = QrCode::create($data['invite_url'])
            ->setEncoding(new Encoding('UTF-8'))
            ->setErrorCorrectionLevel(new ErrorCorrectionLevelLow())
            ->setSize(80)
            ->setMargin(1)
            ->setRoundBlockSizeMode(new RoundBlockSizeModeMargin())
            ->setForegroundColor(new Color(0, 0, 0))
            ->setBackgroundColor(new Color(255, 255, 255));
        $result = $writer->write($qrCode);

        //转换成base64格式
        $data['base64_img'] = $result->getDataUri();

        // 保存为文件
        $result->saveToFile(public_path().DS.'invite'.DS.$data['invite_code'].'.png');

    }


}

